﻿using System;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.EventSystems;

// Token: 0x020003E5 RID: 997
public class GameCursor : Singleton<GameCursor>
{
	// Token: 0x1700025E RID: 606
	// (get) Token: 0x060018D5 RID: 6357 RVA: 0x000A1A90 File Offset: 0x0009FC90
	// (set) Token: 0x060018D6 RID: 6358 RVA: 0x000A1A98 File Offset: 0x0009FC98
	public static bool IsDraw
	{
		get
		{
			return Cursor.visible;
		}
		set
		{
			Cursor.visible = value;
		}
	}

	// Token: 0x1700025F RID: 607
	// (get) Token: 0x060018D7 RID: 6359 RVA: 0x000A1AA0 File Offset: 0x0009FCA0
	// (set) Token: 0x060018D8 RID: 6360 RVA: 0x000A1AA8 File Offset: 0x0009FCA8
	public static Vector2 move { get; private set; }

	// Token: 0x17000260 RID: 608
	// (get) Token: 0x060018D9 RID: 6361 RVA: 0x000A1AB0 File Offset: 0x0009FCB0
	// (set) Token: 0x060018DA RID: 6362 RVA: 0x000A1AB8 File Offset: 0x0009FCB8
	public static Vector2 pos2D { get; private set; }

	// Token: 0x17000261 RID: 609
	// (get) Token: 0x060018DB RID: 6363 RVA: 0x000A1AC0 File Offset: 0x0009FCC0
	public static Vector2 Pos
	{
		get
		{
			return GameCursor.pos;
		}
	}

	// Token: 0x17000262 RID: 610
	// (get) Token: 0x060018DC RID: 6364 RVA: 0x000A1ACC File Offset: 0x0009FCCC
	public static Vector2 RawPos
	{
		get
		{
			return GameCursor.rawPos;
		}
	}

	// Token: 0x17000263 RID: 611
	// (get) Token: 0x060018DD RID: 6365 RVA: 0x000A1AD8 File Offset: 0x0009FCD8
	public static bool IsShortClick
	{
		get
		{
			return GameCursor.shortClick.IsShortClickNow;
		}
	}

	// Token: 0x17000264 RID: 612
	// (get) Token: 0x060018DE RID: 6366 RVA: 0x000A1AE4 File Offset: 0x0009FCE4
	public static bool OnUI
	{
		get
		{
			return EventSystem.current && EventSystem.current.IsPointerOverGameObject();
		}
	}

	// Token: 0x060018DF RID: 6367 RVA: 0x000A1B04 File Offset: 0x0009FD04
	private void Start()
	{
		this.UpdatePos();
		this.Pos3DtoPos2D();
		GameCursor.GetCursorPos(out GameCursor.lockPos);
		this.windowPtr = GameCursor.GetForegroundWindow();
		GameCursor.move = Vector2.zero;
		GameCursor.IsDraw = true;
		GameCursor.isNextLock = false;
		GameCursor.isNowLock = false;
		GameCursor.isPrevLock = false;
		Cursor.SetCursor(this.tex, this.hotspot, CursorMode.Auto);
	}

	// Token: 0x060018E0 RID: 6368 RVA: 0x000A1B68 File Offset: 0x0009FD68
	private void Update()
	{
		this.UpdatePos();
		this.Pos3DtoPos2D();
		GameCursor.shortClick.Update();
		GameCursor.UpdateCursorLock();
	}

	// Token: 0x060018E1 RID: 6369 RVA: 0x000A1B88 File Offset: 0x0009FD88
	private void UpdatePos()
	{
		if (GameCursor.isNowLock)
		{
			GameCursor.move = Vector2.zero;
		}
		else
		{
			GameCursor.move = Input.mousePosition - GameCursor.pos;
			GameCursor.pos = Input.mousePosition;
		}
		GameCursor.POINT point;
		if (GameCursor.GetCursorPos(out point))
		{
			GameCursor.rawPos.x = (float)point.X;
			GameCursor.rawPos.y = (float)point.Y;
		}
	}

	// Token: 0x060018E2 RID: 6370
	[DllImport("USER32.dll", CallingConvention = CallingConvention.StdCall)]
	private static extern void SetCursorPos(int X, int Y);

	// Token: 0x060018E3 RID: 6371
	[DllImport("USER32.dll")]
	[return: MarshalAs(UnmanagedType.Bool)]
	private static extern bool GetCursorPos(out GameCursor.POINT lpPoint);

	// Token: 0x060018E4 RID: 6372
	[DllImport("USER32.dll")]
	private static extern bool ScreenToClient(IntPtr hWnd, ref GameCursor.POINT lpPoint);

	// Token: 0x060018E5 RID: 6373
	[DllImport("USER32.dll")]
	private static extern bool ClientToScreen(IntPtr hWnd, ref GameCursor.POINT lpPoint);

	// Token: 0x060018E6 RID: 6374
	[DllImport("USER32.dll", CallingConvention = CallingConvention.StdCall)]
	private static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

	// Token: 0x060018E7 RID: 6375
	[DllImport("user32.dll")]
	private static extern int MoveWindow(IntPtr hwnd, int x, int y, int nWidth, int nHeight, int bRepaint);

	// Token: 0x060018E8 RID: 6376
	[DllImport("user32.dll")]
	private static extern int GetWindowRect(IntPtr hwnd, ref GameCursor.RECT lpRect);

	// Token: 0x060018E9 RID: 6377
	[DllImport("user32.dll")]
	private static extern IntPtr GetForegroundWindow();

	// Token: 0x060018EA RID: 6378
	[DllImport("user32.dll")]
	private static extern IntPtr FindWindow(string className, string windowName);

	// Token: 0x060018EB RID: 6379 RVA: 0x000A1C04 File Offset: 0x0009FE04
	public void SetCoursorPosition(Vector3 mousePos)
	{
		GameCursor.POINT point = new GameCursor.POINT(0, 0);
		GameCursor.ClientToScreen(this.windowPtr, ref point);
		GameCursor.GetWindowRect(this.windowPtr, ref this.winRect);
		GameCursor.POINT point2 = new GameCursor.POINT(point.X - this.winRect.left, point.Y - this.winRect.top);
		point.X = (int)mousePos.x;
		point.Y = Screen.height - (int)mousePos.y;
		GameCursor.ClientToScreen(this.windowPtr, ref point);
		GameCursor.SetCursorPos(point.X + point2.X, point.Y + point2.Y);
	}

	// Token: 0x060018EC RID: 6380 RVA: 0x000A1CBC File Offset: 0x0009FEBC
	private static void UpdateCursorLock()
	{
		if (GameCursor.isNowLock)
		{
			GameCursor.SetCursorPos(GameCursor.lockPos.X, GameCursor.lockPos.Y);
		}
		if (GameCursor.isNextLock)
		{
			if (!GameCursor.isPrevLock)
			{
				GameCursor.GetCursorPos(out GameCursor.lockPos);
				GameCursor.isNowLock = true;
				GameCursor.IsDraw = false;
				Cursor.lockState = CursorLockMode.Locked;
			}
		}
		else if (GameCursor.isPrevLock)
		{
			Cursor.lockState = CursorLockMode.None;
			GameCursor.SetCursorPos(GameCursor.lockPos.X, GameCursor.lockPos.Y);
			GameCursor.isNowLock = false;
			GameCursor.IsDraw = true;
		}
		GameCursor.isNextLock = false;
		GameCursor.isPrevLock = GameCursor.isNowLock;
	}

	// Token: 0x060018ED RID: 6381 RVA: 0x000A1D68 File Offset: 0x0009FF68
	public static void Lock()
	{
		GameCursor.isNextLock = true;
	}

	// Token: 0x060018EE RID: 6382 RVA: 0x000A1D70 File Offset: 0x0009FF70
	private void Pos3DtoPos2D()
	{
		GameCursor.pos2D = new Vector2(GameCursor.pos.x, (float)Screen.height - GameCursor.pos.y);
	}

	// Token: 0x060018EF RID: 6383 RVA: 0x000A1D98 File Offset: 0x0009FF98
	public void SetCursorLock(bool _flag)
	{
		GameCursor.Lock();
	}

	// Token: 0x04001C37 RID: 7223
	private static Vector3 pos = Vector3.zero;

	// Token: 0x04001C38 RID: 7224
	private static Vector3 rawPos = Vector3.zero;

	// Token: 0x04001C39 RID: 7225
	private static bool isNextLock;

	// Token: 0x04001C3A RID: 7226
	private static bool isNowLock;

	// Token: 0x04001C3B RID: 7227
	private static bool isPrevLock;

	// Token: 0x04001C3C RID: 7228
	private static GameCursor.POINT lockPos = default(GameCursor.POINT);

	// Token: 0x04001C3F RID: 7231
	public Texture2D tex;

	// Token: 0x04001C40 RID: 7232
	public Vector2 size = new Vector2(32f, 32f);

	// Token: 0x04001C41 RID: 7233
	public Vector2 hotspot = Vector2.zero;

	// Token: 0x04001C42 RID: 7234
	private static ShortClick shortClick = new ShortClick();

	// Token: 0x04001C43 RID: 7235
	private const int MOUSEEVENTF_LEFTDOWN = 2;

	// Token: 0x04001C44 RID: 7236
	private const int MOUSEEVENTF_LEFTUP = 4;

	// Token: 0x04001C45 RID: 7237
	private IntPtr windowPtr = GameCursor.GetForegroundWindow();

	// Token: 0x04001C46 RID: 7238
	private GameCursor.RECT winRect = default(GameCursor.RECT);

	// Token: 0x020003E6 RID: 998
	private struct RECT
	{
		// Token: 0x04001C47 RID: 7239
		public int left;

		// Token: 0x04001C48 RID: 7240
		public int top;

		// Token: 0x04001C49 RID: 7241
		public int right;

		// Token: 0x04001C4A RID: 7242
		public int bottom;
	}

	// Token: 0x020003E7 RID: 999
	public struct POINT
	{
		// Token: 0x060018F1 RID: 6385 RVA: 0x000A1DDC File Offset: 0x0009FFDC
		public POINT(int x, int y)
		{
			this.X = x;
			this.Y = y;
		}

		// Token: 0x04001C4B RID: 7243
		public int X;

		// Token: 0x04001C4C RID: 7244
		public int Y;
	}
}
